package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-09-03-20:09
 */
@RestController
public class CustomerController {

    @Autowired
    CustomerService customerService;

    /**
     * 客户列表分页（名称模糊查询）
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @PostMapping("/customer/list")
    public Map<String, Object> listInventory(Integer page, Integer rows, String customerName) {
        return customerService.list(page, rows, customerName);
    }

    /**
     * 增加或更新客户信息，如果 id 为空，为添加； id 存在，则进行更新
     * @param customer
     * @return
     */
    @PostMapping("/customer/save")
    public ServiceVO<Customer> saveOrUpdate(Customer customer){
        return customerService.saveOrUpdate(customer);
    }

    /**
     * 批量删除供应商
     * @param ids 单个或者多个供应商 id     注： ids 为 一个或多个 id 的 String，需要转换为 数组
     * @return
     */
    @PostMapping("/customer/delete")
    public ServiceVO<Customer> deleteById(String ids){
        // 将字符串转为字符串数组
        String[] strings = ids.split(",");

        return customerService.deleteById(strings);
    }

}
